#ifndef PFS_UTIL_H
#define PFS_UTIL_H
#include <stdio.h>
#include <iostream>
#include <stdint.h>
#define return_if_fail(p) if(!(p)) {std::cout<<"Warning:"\
    <<"file:"<<__FILE__<<"func:"<<__func__<<"line:"<<__LINE__<<endl;\
    return;}
#define return_val_if_fail(p, val)  if(!(p)) {std::cout<<"Warning:"\
    <<"file:"<<__FILE__<<"func:"<<__func__<<"line:"<<__LINE__<<endl;\
    return (val);}
#define atomic_get(x) __sync_val_compare_and_swap((x), 0, 0)
#define atomic_add(x ,y) __sync_fetch_and_add((x), (y))
#define atomic_add_return(x, y) __sync_add_and_fetch((x), (y))
#define atomic_inc(x) __sync_fetch_and_add((x), 1)
#define atomic_inc_return(x) __sync_add_and_fetch((x), 1)
#define atomic_sub(x,y) __sync_fetch_and_sub((x), (y))
#define atomic_sub_return(x, y) __sync_sub_and_fetch((x), (y))
#define atomic_dec(x) __sync_fetch_and_sub((x), 1)
#define atomic_dec_return(x) __sync_sub_and_fetch((x), 1)

int64_t write_to_file(int fd, void* buff, size_t len);
int64_t read_from_file(int fd, void* buff, size_t len);

#endif
